package data.dao;

import data.entity.UserEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by Administrator on 2016/11/3.
 */
public class MyJdbcQuery {

    public MyJdbcQuery(JdbcTemplate jdbcTemplate){
        this.jdbcTemplate = jdbcTemplate;
    }
    private JdbcTemplate jdbcTemplate;

    public UserEntity getUser(Integer id) {
        UserEntity user = jdbcTemplate.queryForObject(
                "select * from t_user where id = ?", new BeanPropertyRowMapper<UserEntity>(UserEntity.class), id);
        System.out.println(user.toString());
        return user;
    }

    public UserEntity getUserByName(String userName){
        UserEntity user = jdbcTemplate.queryForObject(
                "select * from t_user where name = ?", new BeanPropertyRowMapper<UserEntity>(UserEntity.class), userName);
        System.out.println(user.toString());
        return user;

    }

}
